#include "DDAS_Client_Result_Data.hpp"

#include <iostream>

using namespace std;

        //structors
      	DDAS_Client_Result_Data::DDAS_Client_Result_Data(){}

        DDAS_Client_Result_Data::DDAS_Client_Result_Data(unsigned int result_count, unsigned int coeff_count)
	{
		this->size 	= result_count;

		this->bin_reps 	= new char*[result_count];
		this->def_nums 	= new char*[result_count];
		this->SSEs 	= new double[result_count];

		//pointers to the coefficients of the results
		this->coefficients = new Coefficients*[result_count];

		//alloc memory for each array of coefficients
		for(int i=0; i<result_count; i++)
		{
			this->coefficients[i] = new Coefficients(coeff_count);
			this->bin_reps[i] = new char[128];
			this->def_nums[i] = new char[128];

			this->SSEs[i]     = 0.0;
		}
	}

        DDAS_Client_Result_Data::~DDAS_Client_Result_Data()
	{
		//delete each char* 
		for(int i=0; i<this->size; i++)
		{
			delete[] this->bin_reps[i];
			delete[] this->def_nums[i];
		}

                //delete each Coefficients*
                for(int i=0; i<this->getRowCount(); i++)
                {
                        delete this->coefficients[i];
                }

		delete[] this->coefficients;
		delete[] this->bin_reps;
		delete[] this->def_nums;
		delete   this->SSEs;
	}


        //getters
        int DDAS_Client_Result_Data::getBinaryRepresentations(char*** bin_reps)
	{
		*bin_reps = this->bin_reps;

		return this->size;
	}

	char* DDAS_Client_Result_Data::getBinaryRepresentation(int index)
	{
		return this->bin_reps[index];
	}

        int DDAS_Client_Result_Data::getDefinitionNumbers(char*** def_nums)
	{
		*def_nums = this->def_nums;

		return this->size;
	}

	char* DDAS_Client_Result_Data::getDefinitionNumber(int index)
	{
		return this->def_nums[index];
	}

        int DDAS_Client_Result_Data::getSSEs(double** SSEs)
	{
		*SSEs = this->SSEs;

		return this->size;
	}

	double DDAS_Client_Result_Data::getSSE(int index)
	{
		return this->SSEs[index];
	}

        int DDAS_Client_Result_Data::getCoefficients(Coefficients*** coeffs)
	{
		*coeffs = this->coefficients;
	}

        int DDAS_Client_Result_Data::getRowCount()
	{
		return this->size;
	}


        //setters
        int DDAS_Client_Result_Data::setBinaryRepresentations(char** bin_reps)
	{
		this->bin_reps = bin_reps;
	}

        int DDAS_Client_Result_Data::setBinaryRepresentation(char* bin_rep, int index)
	{
		strcpy( this->bin_reps[index], bin_rep );
		//this->bin_reps[index] = bin_rep;
	}

        int DDAS_Client_Result_Data::setDefinitionNumbers(char** def_nums)
	{
		this->def_nums = def_nums;
	}

        int DDAS_Client_Result_Data::setDefinitionNumber(char* def_num, int index)
	{
		strcpy( this->def_nums[index], def_num );
		//this->def_nums[index] = def_num;
	}

        int DDAS_Client_Result_Data::setSSEs(double* SSEs)
	{
		this->SSEs = SSEs;
	}

        int DDAS_Client_Result_Data::setSSE(double SSE, int index)
	{
		this->SSEs[index] = SSE;
	}

        int DDAS_Client_Result_Data::setCoefficients(Coefficients*** coeffs)
	{
		this->coefficients = *coeffs;
	}

        int DDAS_Client_Result_Data::setRowCount(unsigned int size)
	{
		this->size = size;
	}
